package com.mavenq.fly.commons.resp;

/**
 * 响应构建者
 */
public class ResponseBuilder<T> {

    private final ResponseObj<T> responseObj = new ResponseObj<>();

    public ResponseBuilder<T> buildMsg(String message) {
        responseObj.setMessage(message);
        return this;
    }

    public ResponseBuilder<T> buildCode(Integer code) {
        responseObj.setCode(code);
        return this;
    }

    public ResponseBuilder<T> buildData(T data) {
        responseObj.setData(data);
        return this;
    }

    public ResponseObj<T> build() {
        return responseObj;
    }

    public static <M> ResponseObj<M> buildSuccess(M data) {
        return new ResponseObj<>(ResponseObj.SUC_MSG, ResponseObj.SUC_CODE, data);
    }

    public static <M> ResponseObj<M> buildFailed() {
        return new ResponseObj<>(ResponseObj.FAIL_MSG, ResponseObj.FAIL_CODE);
    }

    public static <M> ResponseObj<M> buildResponseObj(String message, Integer code, M data) {
        return new ResponseObj<>(message, code, data);
    }

}
